package org.dromara.nursing.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
// import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.nursing.domain.vo.MsAiChatVo;
import org.dromara.nursing.domain.bo.MsAiChatBo;
import org.dromara.nursing.service.IMsAiChatService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * AI聊天
 *
 * @author Lion Li
 * @date 2025-04-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nursing/aiChat")
public class MsAiChatController extends BaseController {

    private final IMsAiChatService msAiChatService;

    /**
     * 查询AI聊天列表
     */
    // @SaCheckPermission("nursing:aiChat:list")
    @GetMapping("/list")
    public TableDataInfo<MsAiChatVo> list(MsAiChatBo bo, PageQuery pageQuery) {
        return msAiChatService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出AI聊天列表
     */
    // @SaCheckPermission("nursing:aiChat:export")
    @Log(title = "AI聊天", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MsAiChatBo bo, HttpServletResponse response) {
        List<MsAiChatVo> list = msAiChatService.queryList(bo);
        ExcelUtil.exportExcel(list, "AI聊天", MsAiChatVo.class, response);
    }

    /**
     * 获取AI聊天详细信息
     *
     * @param id 主键
     */
    // @SaCheckPermission("nursing:aiChat:query")
    @GetMapping("/{id}")
    public R<MsAiChatVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(msAiChatService.queryById(id));
    }

    /**
     * 新增AI聊天
     */
    // @SaCheckPermission("nursing:aiChat:add")
    @Log(title = "AI聊天", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MsAiChatBo bo) {
        return toAjax(msAiChatService.insertByBo(bo));
    }

    /**
     * 修改AI聊天
     */
    // @SaCheckPermission("nursing:aiChat:edit")
    @Log(title = "AI聊天", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MsAiChatBo bo) {
        return toAjax(msAiChatService.updateByBo(bo));
    }

    /**
     * 删除AI聊天
     *
     * @param ids 主键串
     */
    // @SaCheckPermission("nursing:aiChat:remove")
    @Log(title = "AI聊天", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(msAiChatService.deleteWithValidByIds(List.of(ids), true));
    }
}
